package com.guigu.utils;

import com.guigu.ProcureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class NumberUtils1 {

    @Autowired
    private ProcureService procureService;

//    @Autowired
//    private Store_gatherService storeGatherService;

    public String generateDocumentId(String type) {
        StringBuffer buffer = new StringBuffer(type);

        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String temp = format.format(date);
        buffer.append(temp);

        String designId = "";
        switch (type) {
            case "100":
                // 获取最大的物料设计单的编号
                designId = this.procureService.queryProcedureByMaxId();
                break;
//            case "200":
//                designId=this.storeGatherService.selectStoreGatherMaxId();
//                break;
        }
        String flowNumber = "0001";
        if(designId != null) {
            String y1 = designId.substring(3, 7);
            String y2 = date.getYear()+1900 + "";
            if(y1.equals(y2)) {
                int tmp = Integer.parseInt(designId.substring(11)) + 1;
                flowNumber = String.format("%04d",tmp);
            }
        }
        designId = buffer.append(flowNumber).toString();
        return designId;
    }

}
